// 「升级奖励」页面
import { membershipStore } from '@/stores/membership-store';
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings';

Page({
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store: membershipStore,
    fields: { bonusesList: 'showBonusList' },
    actions: ['getMembershipBonusInfo'],
  },
  onLoad() {
    this.init();
  },
  init() {
    if ((this.data.bonusesList?.length || 0) === 0) {
      this.getMembershipBonusInfo();
    }
  },
  /** 奖励项按钮点击事件
   * @param e 事件对象
   */
  onBonusItemBtnClick(e: WechatMiniprogram.TouchEvent) {
    const isUsed = e.currentTarget.dataset.item.isUsed;
    if (isUsed) return;
    const type = e.currentTarget.dataset.item.type as BonusType;
    switch (type) {
      case 'appTx':
        wx.showModal({
          title: '提示',
          content: '奖励已发放至您的“嗨喵APP”账户中\n请登陆“嗨喵APP”提现',
        });
        break;
      case 'contact':
        break;
      case 'yh':
        // 跳转到Wedding Rite小程序
        wx.navigateToMiniProgram({
          appId: 'wx429c18bb8ff2d9cc',
        });
        break;
      case 'gtp':
        // 跳转到婚礼专家小程序
        wx.navigateToMiniProgram({
          appId: 'wx2abb05870f1ba4c7',
        });
        break;
      case 'createActivity':
        wx.navigateTo({
          url: '/pages/index/applyActivity/applyActivity',
        });
        break;
      default:
        break;
    }
  },
});
